﻿using Nest;

namespace Infrastructure.ElasticSearch.Nests
{
    public class ElasticSearchNestBuilder<T, SearchEntity> where T : class where SearchEntity : class
    {
        private ElasticSearchProvider<SearchEntity> _provider;

        public ElasticSearchNestBuilder(ElasticSearchProvider<SearchEntity> provider)
        {
            _provider = provider;
        }

        /// <summary>
        /// 生成查询工具
        /// </summary>
        /// <param name="searchModel"></param>
        /// <returns></returns>
        public ElasticSearchNestRoot<T> Build()
        {
            SearchDescriptor<T> container = new SearchDescriptor<T>();
            container.Query(q => q.Bool(b => _provider.GetBoolQueryDescriptor()));

            return new ElasticSearchNestRoot<T>(container);
        }

    }
}
